{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# (IV) Model Building\n",
    "You can also train the neural network on your data and build and test your own model using the following modules."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1) Training:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can build your own EQTransformer with varying encoder sizes and train it using your own data. Your data should be in the same format as our sample data. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n",
      "/Users/mostafamousavi/anaconda3/envs/test1/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint8 = np.dtype([(\"qint8\", np.int8, 1)])\n",
      "/Users/mostafamousavi/anaconda3/envs/test1/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint8 = np.dtype([(\"quint8\", np.uint8, 1)])\n",
      "/Users/mostafamousavi/anaconda3/envs/test1/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint16 = np.dtype([(\"qint16\", np.int16, 1)])\n",
      "/Users/mostafamousavi/anaconda3/envs/test1/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint16 = np.dtype([(\"quint16\", np.uint16, 1)])\n",
      "/Users/mostafamousavi/anaconda3/envs/test1/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint32 = np.dtype([(\"qint32\", np.int32, 1)])\n",
      "/Users/mostafamousavi/anaconda3/envs/test1/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  np_resource = np.dtype([(\"resource\", np.ubyte, 1)])\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Learning rate:  0.001\n",
      "Model: \"model_1\"\n",
      "__________________________________________________________________________________________________\n",
      "Layer (type)                    Output Shape         Param #     Connected to                     \n",
      "==================================================================================================\n",
      "input (InputLayer)              (None, 6000, 3)      0                                            \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_1 (Conv1D)               (None, 6000, 8)      272         input[0][0]                      \n",
      "__________________________________________________________________________________________________\n",
      "max_pooling1d_1 (MaxPooling1D)  (None, 3000, 8)      0           conv1d_1[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_2 (Conv1D)               (None, 3000, 16)     1168        max_pooling1d_1[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "max_pooling1d_2 (MaxPooling1D)  (None, 1500, 16)     0           conv1d_2[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_3 (Conv1D)               (None, 1500, 16)     1808        max_pooling1d_2[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "max_pooling1d_3 (MaxPooling1D)  (None, 750, 16)      0           conv1d_3[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_4 (Conv1D)               (None, 750, 32)      3616        max_pooling1d_3[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "max_pooling1d_4 (MaxPooling1D)  (None, 375, 32)      0           conv1d_4[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_5 (Conv1D)               (None, 375, 32)      5152        max_pooling1d_4[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "max_pooling1d_5 (MaxPooling1D)  (None, 188, 32)      0           conv1d_5[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_6 (Conv1D)               (None, 188, 64)      10304       max_pooling1d_5[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "max_pooling1d_6 (MaxPooling1D)  (None, 94, 64)       0           conv1d_6[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_7 (Conv1D)               (None, 94, 64)       12352       max_pooling1d_6[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "max_pooling1d_7 (MaxPooling1D)  (None, 47, 64)       0           conv1d_7[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "batch_normalization_1 (BatchNor (None, 47, 64)       256         max_pooling1d_7[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "activation_1 (Activation)       (None, 47, 64)       0           batch_normalization_1[0][0]      \n",
      "__________________________________________________________________________________________________\n",
      "spatial_dropout1d_1 (SpatialDro (None, 47, 64)       0           activation_1[0][0]               \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_8 (Conv1D)               (None, 47, 64)       12352       spatial_dropout1d_1[0][0]        \n",
      "__________________________________________________________________________________________________\n",
      "batch_normalization_2 (BatchNor (None, 47, 64)       256         conv1d_8[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "activation_2 (Activation)       (None, 47, 64)       0           batch_normalization_2[0][0]      \n",
      "__________________________________________________________________________________________________\n",
      "spatial_dropout1d_2 (SpatialDro (None, 47, 64)       0           activation_2[0][0]               \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_9 (Conv1D)               (None, 47, 64)       12352       spatial_dropout1d_2[0][0]        \n",
      "__________________________________________________________________________________________________\n",
      "add_1 (Add)                     (None, 47, 64)       0           max_pooling1d_7[0][0]            \n",
      "                                                                 conv1d_9[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "batch_normalization_3 (BatchNor (None, 47, 64)       256         add_1[0][0]                      \n",
      "__________________________________________________________________________________________________\n",
      "activation_3 (Activation)       (None, 47, 64)       0           batch_normalization_3[0][0]      \n",
      "__________________________________________________________________________________________________\n",
      "spatial_dropout1d_3 (SpatialDro (None, 47, 64)       0           activation_3[0][0]               \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_10 (Conv1D)              (None, 47, 64)       12352       spatial_dropout1d_3[0][0]        \n",
      "__________________________________________________________________________________________________\n",
      "batch_normalization_4 (BatchNor (None, 47, 64)       256         conv1d_10[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "activation_4 (Activation)       (None, 47, 64)       0           batch_normalization_4[0][0]      \n",
      "__________________________________________________________________________________________________\n",
      "spatial_dropout1d_4 (SpatialDro (None, 47, 64)       0           activation_4[0][0]               \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_11 (Conv1D)              (None, 47, 64)       12352       spatial_dropout1d_4[0][0]        \n",
      "__________________________________________________________________________________________________\n",
      "add_2 (Add)                     (None, 47, 64)       0           add_1[0][0]                      \n",
      "                                                                 conv1d_11[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "bidirectional_1 (Bidirectional) (None, 47, 32)       10368       add_2[0][0]                      \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_12 (Conv1D)              (None, 47, 16)       528         bidirectional_1[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "batch_normalization_5 (BatchNor (None, 47, 16)       64          conv1d_12[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "attentionD0 (SeqSelfAttention)  [(None, 47, 16), (No 1089        batch_normalization_5[0][0]      \n",
      "__________________________________________________________________________________________________\n",
      "add_3 (Add)                     (None, 47, 16)       0           batch_normalization_5[0][0]      \n",
      "                                                                 attentionD0[0][0]                \n",
      "__________________________________________________________________________________________________\n",
      "layer_normalization_1 (LayerNor (None, 47, 16)       32          add_3[0][0]                      \n",
      "__________________________________________________________________________________________________\n",
      "feed_forward_1 (FeedForward)    (None, 47, 16)       4240        layer_normalization_1[0][0]      \n",
      "__________________________________________________________________________________________________\n",
      "add_4 (Add)                     (None, 47, 16)       0           layer_normalization_1[0][0]      \n",
      "                                                                 feed_forward_1[0][0]             \n",
      "__________________________________________________________________________________________________\n",
      "layer_normalization_2 (LayerNor (None, 47, 16)       32          add_4[0][0]                      \n",
      "__________________________________________________________________________________________________\n",
      "attentionD (SeqSelfAttention)   [(None, 47, 16), (No 1089        layer_normalization_2[0][0]      \n",
      "__________________________________________________________________________________________________\n",
      "add_5 (Add)                     (None, 47, 16)       0           layer_normalization_2[0][0]      \n",
      "                                                                 attentionD[0][0]                 \n",
      "__________________________________________________________________________________________________\n",
      "layer_normalization_3 (LayerNor (None, 47, 16)       32          add_5[0][0]                      \n",
      "__________________________________________________________________________________________________\n",
      "feed_forward_2 (FeedForward)    (None, 47, 16)       4240        layer_normalization_3[0][0]      \n",
      "__________________________________________________________________________________________________\n",
      "add_6 (Add)                     (None, 47, 16)       0           layer_normalization_3[0][0]      \n",
      "                                                                 feed_forward_2[0][0]             \n",
      "__________________________________________________________________________________________________\n",
      "layer_normalization_4 (LayerNor (None, 47, 16)       32          add_6[0][0]                      \n",
      "__________________________________________________________________________________________________\n",
      "lstm_2 (LSTM)                   (None, 47, 16)       2112        layer_normalization_4[0][0]      \n",
      "__________________________________________________________________________________________________\n",
      "lstm_3 (LSTM)                   (None, 47, 16)       2112        layer_normalization_4[0][0]      \n",
      "__________________________________________________________________________________________________\n",
      "attentionP (SeqSelfAttention)   [(None, 47, 16), (No 1089        lstm_2[0][0]                     \n",
      "__________________________________________________________________________________________________\n",
      "attentionS (SeqSelfAttention)   [(None, 47, 16), (No 1089        lstm_3[0][0]                     \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_1 (UpSampling1D)  (None, 94, 16)       0           layer_normalization_4[0][0]      \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_8 (UpSampling1D)  (None, 94, 16)       0           attentionP[0][0]                 \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_15 (UpSampling1D) (None, 94, 16)       0           attentionS[0][0]                 \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_13 (Conv1D)              (None, 94, 64)       3136        up_sampling1d_1[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_20 (Conv1D)              (None, 94, 64)       3136        up_sampling1d_8[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_27 (Conv1D)              (None, 94, 64)       3136        up_sampling1d_15[0][0]           \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_2 (UpSampling1D)  (None, 188, 64)      0           conv1d_13[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_9 (UpSampling1D)  (None, 188, 64)      0           conv1d_20[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_16 (UpSampling1D) (None, 188, 64)      0           conv1d_27[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_14 (Conv1D)              (None, 188, 64)      20544       up_sampling1d_2[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_21 (Conv1D)              (None, 188, 64)      20544       up_sampling1d_9[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_28 (Conv1D)              (None, 188, 64)      20544       up_sampling1d_16[0][0]           \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_3 (UpSampling1D)  (None, 376, 64)      0           conv1d_14[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_10 (UpSampling1D) (None, 376, 64)      0           conv1d_21[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_17 (UpSampling1D) (None, 376, 64)      0           conv1d_28[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_15 (Conv1D)              (None, 376, 32)      10272       up_sampling1d_3[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_22 (Conv1D)              (None, 376, 32)      10272       up_sampling1d_10[0][0]           \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_29 (Conv1D)              (None, 376, 32)      10272       up_sampling1d_17[0][0]           \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_4 (UpSampling1D)  (None, 752, 32)      0           conv1d_15[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_11 (UpSampling1D) (None, 752, 32)      0           conv1d_22[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_18 (UpSampling1D) (None, 752, 32)      0           conv1d_29[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "cropping1d_1 (Cropping1D)       (None, 750, 32)      0           up_sampling1d_4[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "cropping1d_2 (Cropping1D)       (None, 750, 32)      0           up_sampling1d_11[0][0]           \n",
      "__________________________________________________________________________________________________\n",
      "cropping1d_3 (Cropping1D)       (None, 750, 32)      0           up_sampling1d_18[0][0]           \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_16 (Conv1D)              (None, 750, 32)      7200        cropping1d_1[0][0]               \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_23 (Conv1D)              (None, 750, 32)      7200        cropping1d_2[0][0]               \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_30 (Conv1D)              (None, 750, 32)      7200        cropping1d_3[0][0]               \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_5 (UpSampling1D)  (None, 1500, 32)     0           conv1d_16[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_12 (UpSampling1D) (None, 1500, 32)     0           conv1d_23[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_19 (UpSampling1D) (None, 1500, 32)     0           conv1d_30[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_17 (Conv1D)              (None, 1500, 16)     3600        up_sampling1d_5[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_24 (Conv1D)              (None, 1500, 16)     3600        up_sampling1d_12[0][0]           \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_31 (Conv1D)              (None, 1500, 16)     3600        up_sampling1d_19[0][0]           \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_6 (UpSampling1D)  (None, 3000, 16)     0           conv1d_17[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_13 (UpSampling1D) (None, 3000, 16)     0           conv1d_24[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_20 (UpSampling1D) (None, 3000, 16)     0           conv1d_31[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_18 (Conv1D)              (None, 3000, 16)     2320        up_sampling1d_6[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_25 (Conv1D)              (None, 3000, 16)     2320        up_sampling1d_13[0][0]           \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_32 (Conv1D)              (None, 3000, 16)     2320        up_sampling1d_20[0][0]           \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_7 (UpSampling1D)  (None, 6000, 16)     0           conv1d_18[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_14 (UpSampling1D) (None, 6000, 16)     0           conv1d_25[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "up_sampling1d_21 (UpSampling1D) (None, 6000, 16)     0           conv1d_32[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_19 (Conv1D)              (None, 6000, 8)      1416        up_sampling1d_7[0][0]            \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_26 (Conv1D)              (None, 6000, 8)      1416        up_sampling1d_14[0][0]           \n",
      "__________________________________________________________________________________________________\n",
      "conv1d_33 (Conv1D)              (None, 6000, 8)      1416        up_sampling1d_21[0][0]           \n",
      "__________________________________________________________________________________________________\n",
      "detector (Conv1D)               (None, 6000, 1)      89          conv1d_19[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "picker_P (Conv1D)               (None, 6000, 1)      89          conv1d_26[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "picker_S (Conv1D)               (None, 6000, 1)      89          conv1d_33[0][0]                  \n",
      "==================================================================================================\n",
      "Total params: 258,983\n",
      "Trainable params: 258,439\n",
      "Non-trainable params: 544\n",
      "__________________________________________________________________________________________________\n",
      "Started training in generator mode ...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/10\n",
      "Learning rate:  0.001\n",
      "6/6 [==============================] - 22s 4s/step - loss: 0.5562 - detector_loss: 0.5865 - picker_P_loss: 0.4657 - picker_S_loss: 0.6175 - detector_f1: 0.0443 - picker_P_f1: 2.1523e-04 - picker_S_f1: 6.0200e-05 - val_loss: 0.2749 - val_detector_loss: 0.4683 - val_picker_P_loss: 0.0789 - val_picker_S_loss: 0.3978 - val_detector_f1: 0.0000e+00 - val_picker_P_f1: 0.0000e+00 - val_picker_S_f1: 0.0000e+00\n",
      "\n",
      "Epoch 00001: val_loss improved from inf to 0.27486, saving model to /Users/mostafamousavi/Desktop/EQTransformer/examples/test_trainer_outputs/models/test_trainer_001.h5\n",
      "Epoch 2/10\n",
      "Learning rate:  0.001\n",
      "6/6 [==============================] - 5s 898ms/step - loss: 0.1360 - detector_loss: 0.5519 - picker_P_loss: 0.0574 - picker_S_loss: 0.1532 - detector_f1: 0.0000e+00 - picker_P_f1: 0.0000e+00 - picker_S_f1: 0.0000e+00 - val_loss: 0.0766 - val_detector_loss: 0.4950 - val_picker_P_loss: 0.0645 - val_picker_S_loss: 0.0450 - val_detector_f1: 0.0000e+00 - val_picker_P_f1: 0.0000e+00 - val_picker_S_f1: 0.0000e+00\n",
      "\n",
      "Epoch 00002: val_loss improved from 0.27486 to 0.07655, saving model to /Users/mostafamousavi/Desktop/EQTransformer/examples/test_trainer_outputs/models/test_trainer_002.h5\n",
      "Epoch 3/10\n",
      "Learning rate:  0.001\n",
      "6/6 [==============================] - 5s 886ms/step - loss: 0.0971 - detector_loss: 0.5304 - picker_P_loss: 0.0763 - picker_S_loss: 0.0705 - detector_f1: 0.0000e+00 - picker_P_f1: 0.0000e+00 - picker_S_f1: 0.0000e+00 - val_loss: 0.0854 - val_detector_loss: 0.4564 - val_picker_P_loss: 0.0644 - val_picker_S_loss: 0.0645 - val_detector_f1: 0.0000e+00 - val_picker_P_f1: 0.0000e+00 - val_picker_S_f1: 0.0000e+00\n",
      "\n",
      "Epoch 00003: val_loss did not improve from 0.07655\n",
      "Epoch 4/10\n",
      "Learning rate:  0.001\n",
      "6/6 [==============================] - 5s 877ms/step - loss: 0.0980 - detector_loss: 0.5263 - picker_P_loss: 0.0740 - picker_S_loss: 0.0741 - detector_f1: 0.0000e+00 - picker_P_f1: 0.0000e+00 - picker_S_f1: 0.0000e+00 - val_loss: 0.0856 - val_detector_loss: 0.4615 - val_picker_P_loss: 0.0643 - val_picker_S_loss: 0.0644 - val_detector_f1: 0.0000e+00 - val_picker_P_f1: 0.0000e+00 - val_picker_S_f1: 0.0000e+00\n",
      "\n",
      "Epoch 00004: val_loss did not improve from 0.07655\n"
     ]
    }
   ],
   "source": [
    "from EQTransformer.core.trainer import trainer\n",
    "trainer(input_hdf5='../ModelsAndSampleData/100samples.hdf5',\n",
    "        input_csv='../ModelsAndSampleData/100samples.csv',\n",
    "        output_name='test_trainer',                \n",
    "        cnn_blocks=2,\n",
    "        lstm_blocks=1,\n",
    "        padding='same',\n",
    "        activation='relu',\n",
    "        drop_rate=0.2,\n",
    "        label_type='gaussian',\n",
    "        add_event_r=0.6,\n",
    "        add_gap_r=0.2,\n",
    "        shift_event_r=0.9,\n",
    "        add_noise_r=0.5, \n",
    "        mode='generator',\n",
    "        train_valid_test_split=[0.60, 0.20, 0.20],\n",
    "        batch_size=20,\n",
    "        epochs=10, \n",
    "        patience=2,\n",
    "        gpuid=None,\n",
    "        gpu_limit=None)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2) Test Your Model:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can then test the model you just trained based on the ground truth labels:  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loading the model ...\n",
      "Loading is complete!\n",
      "Testing ...\n",
      "Writting results into: \" test_tester_outputs \"\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 2/2 [00:09<00:00,  4.74s/it]"
     ]
    }
   ],
   "source": [
    "from EQTransformer.core.tester import tester\n",
    "tester(input_hdf5='../ModelsAndSampleData/100samples.hdf5',\n",
    "       input_testset='test_trainer_outputs/test.npy',\n",
    "       input_model='test_trainer_outputs/models/test_trainer_001.h5',\n",
    "       output_name='test_tester',\n",
    "       detection_threshold=0.20,                \n",
    "       P_threshold=0.1,\n",
    "       S_threshold=0.1, \n",
    "       number_of_plots=3,\n",
    "       estimate_uncertainty=True, \n",
    "       number_of_sampling=2,\n",
    "       input_dimention=(6000, 3),\n",
    "       normalization_mode='std',\n",
    "       mode='generator',\n",
    "       batch_size=10,\n",
    "       gpuid=None,\n",
    "       gpu_limit=None)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
